﻿#include <stdio.h>
#include <string.h>

typedef enum {
    IDLE,
    SEARCHING,
    APPLYING,
    INTERVIEWING,
    HIRED
} State;

typedef struct {
    State currentState;
} StateMachine;

void transition(StateMachine* sm, const char* action) {
    switch (sm->currentState) {
    case IDLE:
        if (strcmp(action, "search") == 0) {
            sm->currentState = SEARCHING;
            printf("Transitioning to Searching...\n");
        }
        else {
            printf("Invalid action in Idle state.\n");
        }
        break;

    case SEARCHING:
        if (strcmp(action, "apply") == 0) {
            sm->currentState = APPLYING;
            printf("Transitioning to Applying...\n");
        }
        else if (strcmp(action, "cancel") == 0) {
            sm->currentState = IDLE;
            printf("Transitioning back to Idle...\n");
        }
        else {
            printf("Invalid action in Searching state.\n");
        }
        break;

    case APPLYING:
        if (strcmp(action, "interview") == 0) {
            sm->currentState = INTERVIEWING;
            printf("Transitioning to Interviewing...\n");
        }
        else if (strcmp(action, "cancel") == 0) {
            sm->currentState = SEARCHING;
            printf("Transitioning back to Searching...\n");
        }
        else {
            printf("Invalid action in Applying state.\n");
        }
        break;

    case INTERVIEWING:
        if (strcmp(action, "hire") == 0) {
            sm->currentState = HIRED;
            printf("Transitioning to Hired...\n");
        }
        else if (strcmp(action, "reject") == 0) {
            sm->currentState = SEARCHING;
            printf("Transitioning back to Searching...\n");
        }
        else {
            printf("Invalid action in Interviewing state.\n");
        }
        break;

    case HIRED:
        printf("Already hired. No further actions can be taken.\n");
        break;

    default:
        printf("Unknown state.\n");
        break;
    }
}

const char* getStateName(State state) {
    switch (state) {
    case IDLE: return "Idle";
    case SEARCHING: return "Searching";
    case APPLYING: return "Applying";
    case INTERVIEWING: return "Interviewing";
    case HIRED: return "Hired";
    default: return "Unknown";
    }
}

int main() {
    StateMachine sm;
    sm.currentState = IDLE;

    printf("Current State: %s\n", getStateName(sm.currentState));

    transition(&sm, "search");
    printf("Current State: %s\n", getStateName(sm.currentState));

    transition(&sm, "apply");
    printf("Current State: %s\n", getStateName(sm.currentState));

    transition(&sm, "interview");
    printf("Current State: %s\n", getStateName(sm.currentState));

    transition(&sm, "hire");
    printf("Current State: %s\n", getStateName(sm.currentState));

    transition(&sm, "search"); 

    return 0;
}
